/*
 * @author: wizardc
 */

using Dou.ScreenController;
using Dou.UI;
using UnityEditor;
using UnityEngine;

namespace DouEditor.ScreenController
{
    [CustomEditor(typeof(DTextMeshProUGUIAdapter))]
    public class DTextMeshProUGUIAdapterEditor : Editor
    {
        private DTextMeshProUGUIAdapter _target;
        private DTextMeshProUGUI _textMeshProUGUI;

        private void OnEnable()
        {
            _target = (DTextMeshProUGUIAdapter) target;
            _textMeshProUGUI = _target.GetComponent<DTextMeshProUGUI>();
            
            var uiScreenMode = ScreenControllerMgr.GetScreenMode();
            var uiFineTuningMode = ScreenControllerMgr.GetFineTuningMode();
            
            _target.fontSetting.Init(uiScreenMode, uiFineTuningMode, _textMeshProUGUI.fontSetting);
            _target.fontSize.Init(uiScreenMode, uiFineTuningMode, _textMeshProUGUI.fontSize);
            _target.overflowMode.Init(uiScreenMode, uiFineTuningMode, _textMeshProUGUI.overflowMode);
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            
            var color = GUI.color;
            var col = ScreenControllerMgr.DrawScreenModeLabel();
            GUI.color = col;

            var fontSetting = AdapterEditorUtil.DrawObjectField(_textMeshProUGUI.fontSetting, _target.fontSetting, "字体设定");
            _textMeshProUGUI.fontSetting = fontSetting;
            
            var fontSize = AdapterEditorUtil.DrawFloatField(_textMeshProUGUI.fontSize, _target.fontSize, "字号");
            _textMeshProUGUI.fontSize = fontSize;

            var overflowMode = AdapterEditorUtil.DrawEnumField(_textMeshProUGUI.overflowMode, _target.overflowMode, "超框模式");
            _textMeshProUGUI.overflowMode = overflowMode;
            
            serializedObject.ApplyModifiedProperties();
            
            GUI.color = color;
        }
    }
}
